package com.app.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.app.model.ProblemReflection;
import com.app.page.CommonPage;
import com.app.request.PageParamRequest;
import com.app.request.ProblemRequest;
import com.app.response.ArticleResponse;
import com.app.result.CommonResult;
import com.app.service.IProblemReflectionService;
import com.app.util.Result;
import com.app.util.WechatUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.login.LoginException;
import java.time.LocalDateTime;

/**
 * <p>
 * 问题反映 前端控制器
 * </p>
 *
 * @author ghoul
 * @since 2024-12-17
 */
@RestController
@RequestMapping("/problemReflection")
public class ProblemReflectionController {
    @Autowired
    private IProblemReflectionService problemReflectionService;
    @Autowired
    private WechatUtil wechatUtil;

    /**
     * 列表
     *
     * @param request
     * @param pageParamRequest
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<ProblemReflection>> getList(@Validated ProblemRequest request, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(problemReflectionService.getAdminList(request, pageParamRequest)));
    }

    /**
     * 新增
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated ProblemReflection request) {
        if (problemReflectionService.create(request)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(Integer id) {
        if (problemReflectionService.deleteById(id)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<ArticleResponse> info(Integer id) {
        return CommonResult.success(problemReflectionService.getDetail(id));
    }

    /**
     * 获取手机号
     * @param code
     * @return
     */
    @GetMapping("/getPhone")
    public Result getPhone(String code) {
        String mobile = wechatUtil.getMobile(code);
        return Result.success(mobile);
    }
}

